package cn.wolfcode.p2p.base.domain;

import cn.wolfcode.p2p.util.Constants;
import lombok.Getter;
import lombok.Setter;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

/**
 * 个人账户表
 */
@Setter@Getter
@Component
public class Account extends BaseDomain{

    private String tradePassword;//交易密码

    private BigDecimal usableAmount = Constants.ZERO;//账户可用余额

    private BigDecimal freezedAmount  = Constants.ZERO;//账户冻结金额

    private BigDecimal borrowLimitAmount = Constants.DEFAULT_BORROW_LIMIT;//账户授信额度

    private Integer version = 0; //版本

    private BigDecimal unReceiveInterest  = Constants.ZERO; //账户待收利息

    private BigDecimal unReceivePrincipal  = Constants.ZERO;//账户待收本金

    private BigDecimal unReturnAmount  = Constants.ZERO; //账户待还金额

    private BigDecimal remainBorrowLimit = Constants.DEFAULT_BORROW_LIMIT; //账户剩余授信额度

    public BigDecimal getTotalAmount(){
        return usableAmount.add(freezedAmount).add(unReceivePrincipal);
    }

    /**
     * 增加账户可用余额
     * @param amount
     */
    public void addUsableAmount(BigDecimal amount) {
       this.usableAmount = this.getUsableAmount().add(amount);
    }
    /**
     * 账户可用余额 - amount
     * @param amount
     */
    public void subtractUsableAmount(BigDecimal amount) {
       this.usableAmount = this.getUsableAmount().subtract(amount);
    }
    /**
     * 账户冻结资金增加
     * @param amount
     */
    public void addFreezedAmount(BigDecimal amount) {
       this.freezedAmount = this.freezedAmount.add(amount);
    }
    /**
     * 账户冻结资金减少 - amount
     * @param amount
     */
    public void subtractFreezedAmount(BigDecimal amount) {
       this.freezedAmount = this.freezedAmount.subtract(amount);
    }
}